script_enemy_main{

let shot1=0;
let bullet1=[];
let timer1=[];
let alpha1=[];

let frame2=0;
let angle2=0;

let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let frame=-90;
let time=-90;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;
let GRboss=("\script\Images\CharacterSprites\Sayuri.png");

let SEshots6=("\script\SoundEffects\shots6.wav");
let SEshotm3=("\script\SoundEffects\shotm3.wav");

@Initialize{
	LoadGraphic("\script\Images\CharacterSprites\Sayuri.png");

	SetLife(10000);
	SetColor(255,190,40);
	Concentration01(90);
	SetColor(255,255,255);
	SetX(GetCommonData("Boss1X"));
	SetY(GetCommonData("Boss1Y"));
	SetMovePosition02(cx-100,miny+120,50);
}
	
@MainLoop{

SetCollisionB(GetX,GetY,16);
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=10; }
SetDamageRate(damagerate,damagerate);

if(time%20==0){ SetMovePosition02(cx+100*cos(time),miny+100+40*sin(time),50); }


if(GetCommonData("Difficulty")==3){

if(frame>=100 && frame<=150 && frame%25==0 && time>=60){
let angle=time+rand(-5,5);
	loop(40){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,3.5);
	ObjShot_SetDelay(shot1,30);
	ObjShot_SetGraphic(shot1,38);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	alpha1=alpha1~[shot1];
	alpha1[length(bullet1)-1]=0;
	angle+=360/40;
	}
PlaySE(SEshotm3);
}

if(time>=60){
let i=0;
	while(i<length(bullet1)){
		if(Obj_BeDeleted(bullet1[i])){
		bullet1=erase(bullet1,i); timer1=erase(timer1,i); alpha1=erase(alpha1,i);
		i--;
		}
		else{
		Obj_SetAlpha(bullet1[i],alpha1[i]);
		if(alpha1[i]<255 && timer1[i]>50){ alpha1[i]=alpha1[i]+3; }
		timer1[i]=timer1[i]+1;
		}
	i++;
	}
}

if(frame==150){ frame=0; }

if(frame2>=30 && frame2<150 && time%3==0 && time>=60){
let shot1=0;
let direction=-15;
	loop(2){
	CreateShotA(shot1,GetX+15,GetY-35,0);
	SetShotDataA(shot1,0,3.5,angle2,0,-0.1,0,83);
	SetShotDirectionType(PLAYER);
	SetShotDataA(shot1,120,0,direction,0,0.1,5,83);
	SetShotDirectionType(ABSOLUTE);
	FireShot(shot1);
	direction+=30;
	}
angle2-=360/40;
usespell=5;
PlaySE(SEshots6);
}

if(frame2==300){ frame2=0; }

} // Hard

//=============================================================================================================

if(GetCommonData("Difficulty")==4){

if(frame>=90 && frame<135 && frame%15==0 && time>=60){
let angle=time+rand(-5,5);
	loop(50){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,3.5);
	ObjShot_SetDelay(shot1,30);
	ObjShot_SetGraphic(shot1,38);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	alpha1=alpha1~[shot1];
	alpha1[length(bullet1)-1]=0;
	angle+=360/50;
	}
PlaySE(SEshotm3);
}

if(time>=60){
let i=0;
	while(i<length(bullet1)){
		if(Obj_BeDeleted(bullet1[i])){
		bullet1=erase(bullet1,i); timer1=erase(timer1,i); alpha1=erase(alpha1,i);
		i--;
		}
		else{
		Obj_SetAlpha(bullet1[i],alpha1[i]);
		if(alpha1[i]<255 && timer1[i]>65){ alpha1[i]=alpha1[i]+4; }
		timer1[i]=timer1[i]+1;
		}
	i++;
	}
}

if(frame==120){ frame=0; }

if(frame2>=30 && frame2<150 && time%3==0 && time>=60){
let shot1=0;
let direction=-10;
	loop(2){
	CreateShotA(shot1,GetX+15,GetY-35,0);
	SetShotDataA(shot1,0,5,angle2,0,-0.1,0,83);
	SetShotDirectionType(PLAYER);
	SetShotDataA(shot1,120,0,direction,0,0.1,5,83);
	SetShotDirectionType(ABSOLUTE);
	FireShot(shot1);
	direction+=20;
	}
angle2-=360/40;
usespell=5;
PlaySE(SEshots6);
}

if(frame2==300){ frame2=0; }

} //Lunatic


time++;
frame++;
frame2++;

if(usespell>0){ usespell--; }
if(usespell<0){ usespell++; }

SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY); 
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
	CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,"Sayuri");
}
}